package com.code.wflow.wrapper;

import com.code.wflow.constants.ResultCode;
import lombok.Data;

/**
 * @author ggh
 * @date 2023/3/5
 */
@Data
public class Result<T> {
    private String code;

    private String msg;

    private T data;

    private Result() {
    }

    public static <R> Result<R> failure(String errorCode) {
        return failure(errorCode);
    }

    public static <R> Result<R> failure(ResultCode resultCode) {
        return result(resultCode.getCode(), resultCode.getMessage(), null);
    }

    public static <T> Result ok(T data) {
        return result(ResultCode.SUCCESS.getCode(), null, data);
    }

    public static <T> Result result(String errorCode, String msg, T data) {
        Result result = new Result();
        result.code = errorCode;
        result.msg = msg;
        result.data = data;
        return result;
    }
}

